package com.ee.chat.api.controller;

import com.ee.chat.api.service.IDynamicService;
import com.ee.chat.common.bean.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("dynamic")
public class DynamicController {
    private Logger log = LoggerFactory.getLogger(DynamicController.class);

    @Resource
    IDynamicService dynamicService;

    /**
     * 获取社区动态
     * @Author Shane
     * @Date 2019/8/316:06
     * @param type  类型，0-热门  1-最新  2-附近  3-私密视频  4-私密图片
     * @param id    起始动态id
     * @return
     **/
    @RequestMapping("getDynamics")
    public Result getDynamics(@RequestParam(required = false) String token, @RequestParam Integer type, @RequestParam(required = false) Integer id,
                              @RequestParam(required = false) String location,
                              @RequestParam(defaultValue = "1") Integer page,
                              @RequestParam(defaultValue = "10") Integer limit){
        try {
            return dynamicService.getDynamics(token, type, id, location, page, limit);
        } catch (Exception e){
            log.error("【获取动态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 动态点赞
     * @Author Shane
     * @Date 2020/3/29 11:32
     * @param id    动态id
     * @param like  0-取消点赞，1-点赞
     * @return
     */
    @RequestMapping("likeDynamic")
    public Result likeDynamic(@RequestParam String token, @RequestParam Integer id, @RequestParam Integer like){
        try {
            return dynamicService.likeDynamic(token, id, like);
        } catch (Exception e){
            log.error("【点赞/取消点赞错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 购买动态
     * @Author Shane
     * @Date 2019/8/2314:48
     * @param
     * @return
     **/
    @RequestMapping("buyDynamic")
    public Result buyDynamic(@RequestParam String token, @RequestParam Integer id){
        try {
            return dynamicService.buyDynamic(token, id);
        } catch(Exception e){
            log.error("【购买动态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 获取动态价格列表
     * @Author Shane
     * @Date 2019/10/8 18:33
     * @param type  动态类型，0-图片  1-视频
     * @return
     */
    @RequestMapping("getDynamicCharge")
    public Result getDynamicCharge(@RequestParam String token, Integer type){
        try {
            return dynamicService.getDynamicCharge(token, type);
        } catch (Exception e){
            log.error("【获取动态价格错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 发布动态
     * @Author Shane
     * @Date 2019/10/8 20:04
     * @param dynamic   动态资源路径
     * @param type  动态类型，0-图片  1-视频
     * @param chargeId  收费价格id，0表示免费
     * @param address   地址
     * @param location  经纬度
     * @return
     */
    @RequestMapping("publishDynamic")
    public Result publishDynamic(@RequestParam String token, @RequestParam String title, @RequestParam String dynamic, @RequestParam Integer type,
                                 @RequestParam Integer chargeId, String address, String location){
        try {
            return dynamicService.publishDynamic(token, title, dynamic, type, chargeId, address, location);
        } catch (Exception e){
            log.error("【发布动态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 修改动态价格
     * @Author Shane
     * @Date 2019/10/8 20:07
     * @param id 动态id
     * @param chargeId  价格id
     * @return
     */
    @RequestMapping("updDynamicCharge")
    public Result updDynamicCharge(@RequestParam String token, @RequestParam Integer id, @RequestParam Integer chargeId){
        try {
            return dynamicService.updDynamicCharge(token, id, chargeId);
        } catch (Exception e){
            log.error("【修改动态价格错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 删除动态
     * @Author Shane
     * @Date 2019/10/8 20:09
     * @param id 动态id
     * @return
     */
    @RequestMapping("delDynamic")
    public Result delDynamic(@RequestParam String token, @RequestParam Integer id){
        try {
            return dynamicService.delDynamic(token, id);
        } catch (Exception e){
            log.error("【删除动态错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 添加动态观看记录
     * @Author Shane
     * @Date 2019/10/10 21:35
     * @param id 动态id
     * @return
     */
    @RequestMapping("addWatchLog")
    public Result addWatchLog(@RequestParam String token, @RequestParam Integer id){
        try {
            return dynamicService.addWatchLog(token, id);
        } catch (Exception e){
            log.error("【添加动态观看记录错误】", e);
        }
        return Result.returnFailure();
    }

    /**
     * 地点输入提示
     * @param token
     * @param location  用户位置，如40.047857537164,116.31353434477
     * @param search    关键字
     * @return
     */
    @RequestMapping("adderSuggestion")
    public Result adderSuggestion(@RequestParam String token, @RequestParam String city, @RequestParam String location, @RequestParam String search){
        try {
            return dynamicService.adderSuggestion(token, city, location, search);
        } catch (Exception e){
            log.error("【地点输入提示错误】", e);
        }
        return Result.returnFailure();
    }

}
